<?php include $this->admin_tpl('header');?>
<body class="pear-container">
<div class="layui-card">
    <div class="layui-card-body">
        <div class="layui-row hui-form-search">
            <form class="layui-form layui-col-md12" action="javascript:;" id="form_admin_search">
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <input type="text" name="user_name" id="user_name" placeholder="请输入用户名" autocomplete="off"
                               class="layui-input">
                    </div>

                    <div class="layui-inline" style="width:120px;">
                        <select name="status" id="status">
                            <option value="">==是否成功==</option>
                            <option value="1">成功</option>
                            <option value="0">失败</option>
                        </select>
                    </div>
                    <div class="layui-inline">
                        <button class="layui-btn layui-btn-md" data-type="reload" lay-submit="" lay-filter="search">
                            <i class="layui-icon layui-icon-search"></i>搜索
                        </button>
                        <button class="layui-btn layui-btn-danger layui-btn-md reset" type="reset">
                            <i class="layui-icon">&#xe63f;</i>清空
                        </button>
                    </div>

                </div>
            </form>
        </div>
    </div>
</div>

<script type="text/html" id="add_toolbar">
    <button class="pear-btn pear-btn-warming pear-btn-md"
            data-delete="<?php echo U('log/loginLogDel',['type'=>0]); ?>"
            data-title="删除超过一个月" data-reload="2">
        <i class="layui-icon layui-icon-delete"></i>
        删除超过一个月
    </button>
    <button class="pear-btn pear-btn-danger pear-btn-md"
            data-delete="<?php echo U('log/loginLogDel',['type'=>1]); ?>"
            data-title="全部删除" data-reload="2">
        <i class="layui-icon layui-icon-delete"></i>
        全部删除
    </button>
</script>

<div class="layui-card">
    <div class="layui-card-body">
        <table id="table_list" lay-filter="table_list"></table>
    </div>
</div>

<?php include $this->admin_tpl('footer');?>
<script>
  layui.use(['table', 'jquery', 'drawer'], function () {
    var $ = layui.jquery;
    var table = layui.table;
    table.render({
      elem: '#table_list'
      , toolbar: '#add_toolbar'
      , defaultToolbar: [{
        layEvent: 'refresh',
        icon: 'layui-icon-refresh',
        title: '刷新'
      }, 'filter', 'exports']
      , method: 'get'
      , url: "<?php echo U('log/loginLogList'); ?>"
      , parseData: function (res) {
        return {
          "code": res.lay_code,
          "msg": res.msg,
          "count": res.count,
          "data": res.data
        };
      }
      , cellMinWidth: 100
      , cols: [[
        {field: 'username', title: '用户名', width: 120}
        , {field: 'password', title: '登录密码', minWidth: 120}
        , {field: 'login_ip', title: 'IP地址', width: 170, align: 'center'}
        , {
          field: 'status', title: '登录状态', width: 80, align: 'center', templet: function (d) {
            if (d.login_result === 1) {
              return '<span class="layui-badge layui-bg-cyan ">成功</span>';
            } else {
              return '<span class="layui-badge-rim layui-bg-red">失败</span>';
            }
          }
        }
        , {field: 'cause', title: '描述', minWidth: 170}
        , {field: 'login_time', title: '登录时间', width: 170}
      ]]
      , id: 'testReload'
      , page: true
      , limit: 10
    });
    var $ = layui.$, active = {
      reload: function () {
        //执行重载
        table.reload('testReload', {
          page: {curr: 1},
          where: {
            key: {
              user_name: $('#user_name').val(),
              status: $('#status').val(),
            }
          }
        });
      }
    };
    //监听排序
    table.on('sort(table_list)', function (obj) {
      table.reload('testReload', {
        initSort: obj
        , where: {
          field: obj.field
          , order: obj.type
        }
      });
    });

    $('.hui-form-search .layui-btn').on('click', function () {
      var type = $(this).data('type');
      active[type] ? active[type].call(this) : '';
    });
    $('.hui-form-search .reset').on('click', function () {
      window.location.reload();
    });

    //监听行工具事件
    table.on('toolbar(table_list)', function (obj) {
      console.log(obj);
      if (obj.event === 'refresh') {
        table.reload('testReload');
      }
    });

  });
</script>
</body>
</html>
